package org.nox.helloseries.core.console;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.nox.helloseries.core.AbstractHelloSeriesTest;
import org.nox.helloseries.core.exceptions.TrackerSearchException;
import org.nox.helloseries.core.services.recherche.TrackerSearchService;
import org.nox.helloseries.core.services.recherche.TrackerSearchServiceTest;
import org.nox.helloseries.domain.NomTracker;
import org.nox.helloseries.domain.Qualite;
import org.nox.helloseries.domain.Serie;
import org.nox.helloseries.domain.Tracker;
import org.nox.helloseries.domain.Version;
import org.nox.helloseries.factory.HelloSeriesServiceFactory;
import org.nox.helloseries.util.SeriePrettyPrinter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TrackerSearchCalls extends AbstractHelloSeriesTest
{
    private static final Logger LOG = LoggerFactory.getLogger( TrackerSearchServiceTest.class );

    private TrackerSearchService trackerSearchService = HelloSeriesServiceFactory.createOrGetService( TrackerSearchService.class );;

    @Test
    public void searchEZTV_test() throws TrackerSearchException
    {
        Serie serieARechercher = new Serie( "Heroes.S03E02" );
        Tracker tracker = new Tracker();
        tracker.setNomTracker( NomTracker.EZTV );

        // Récupération des configurations
        List<Serie> retour = trackerSearchService.getSeriesToBeDownloaded( serieARechercher, tracker );

        LOG.debug( "Séries trouvées sur EZTV " + SeriePrettyPrinter.rssPrettyPrint( retour ) );
    }

    @Test
    public void searchFTDB_test()
    {
        Serie serieARechercher = new Serie( "Louie.S04E11" );
        serieARechercher.setVersion( Version.VO );
        serieARechercher.setQualite( Qualite._720P );
        Tracker tracker = new Tracker();
        tracker.setNomTracker( NomTracker.FRENCHTORRENTDB );

        // Récupération des configurations
        try
        {
            List<Serie> retour = trackerSearchService.getSeriesToBeDownloaded( serieARechercher, tracker );
            LOG.debug( "Séries trouvées sur FTDB " + SeriePrettyPrinter.rssPrettyPrint( retour ) );
        }
        catch ( TrackerSearchException e )
        {
            LOG.error( e.getMessage() );
            Assert.fail( "Impossible de récuperer les données sur le tracker " + tracker.getNomTracker() );
        }
    }

}
